package com.app.backend.config.jpa;

import com.app.backend.common.utils.RequestContextHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;

import java.util.Optional;

/**
 * @program: UserAudit
 * @description: bean中创建及更新的用户自动填充
 * @author: Zhun.Xiao
 * @create: 2020-02-08 13:02
 **/
@Configuration
public class UserAudit implements AuditorAware<String> {

    @Override
    public Optional<String> getCurrentAuditor() {
        //todo 从threadlocal 或者 spring securityContextHolder 或者shiro 中获取 当前访问的用户名
        String username = RequestContextHandler.getCurrentUserName();
        Optional<String> optional = Optional.ofNullable(username);
        return optional;
    }
}